﻿package mortal.game.view.copy.crossMainCity.mainCityPosition
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.display.*;
    import flash.geom.*;
    import frEngine.primitives.object2d.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.crossMainCity.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;

    public class MainCityPostionPanel extends GSprite
    {
        private var _bg:GImageBitmap;
        private var _postList:Array;
        private var playerVec:Vector.<Model3dBasePanel>;
        private var _effectVec:Vector.<EffectPlayer>;
        protected var _img2d:Img2D;
        protected var _rect3d:Rect3DObject;
        private var _window:Window;
        private var _posArr:Array;

        public function MainCityPostionPanel(param1:Window)
        {
            this._postList = [];
            this.playerVec = new Vector.<Model3dBasePanel>;
            this._effectVec = new Vector.<EffectPlayer>;
            this._posArr = [2, 4, 5, 3, 1];
            this._window = param1;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.MainCityWinBg, 0, 0, null, this.add2d);
            NetDispatcher.addCmdListener(ServerCommand.MainCityPostionInfoGet, this.updateList);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.MainCityPostionInfoGet, this.updateList);
            this.removeList();
            this.clear3dRole();
            this._bg.dispose(param1);
            this._bg = null;
            if (this._img2d)
            {
                this._img2d.dispose();
                this._img2d = null;
            }
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            this.playerVec.length = 0;
            this._postList.length = 0;
            this._effectVec.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function clear3dRole() : void
        {
            var _loc_1:Model3dBasePanel = null;
            for each (_loc_1 in this.playerVec)
            {
                
                _loc_1.dispose();
            }
            this.playerVec.length = 0;
            return;
        }// end function

        private function add2d() : void
        {
            var _loc_1:BitmapData = null;
            if (this.isDisposed)
            {
                return;
            }
            this.add3d();
            this.createPosList();
            if (this._rect3d)
            {
                _loc_1 = this._bg.bitmapData;
                this._img2d = new Img2D(null, _loc_1, new Rectangle(0, 0, 881, 543), false);
                this._rect3d.addImg(this._img2d);
            }
            GameProxy.guild.getMainCityPostionInfo();
            return;
        }// end function

        private function add3d() : void
        {
            this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(9, 67, 881, 543), this._window);
            Rect3DManager.instance.windowShowHander(null, this._window);
            return;
        }// end function

        private function removeList() : void
        {
            var _loc_1:MainCityPostRender = null;
            var _loc_2:EffectPlayer = null;
            for each (_loc_1 in this._postList)
            {
                
                _loc_1.dispose();
            }
            this._postList.length = 0;
            for each (_loc_2 in this._effectVec)
            {
                
                this._rect3d.disposeObj3d(_loc_2);
            }
            this._effectVec.length = 0;
            return;
        }// end function

        private function createPosList() : void
        {
            var _loc_1:MainCityPostRender = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            while (_loc_3 < 5)
            {
                
                _loc_1 = UICompomentPool.getUICompoment(MainCityPostRender);
                _loc_1.x = _loc_3 * 170 + 7;
                _loc_1.y = Math.abs(_loc_3 - 2) * 70 + 365;
                this._window.contentTopOf3DSprite.addChild(_loc_1);
                this._postList.push(_loc_1);
                _loc_2 = this._posArr.indexOf((_loc_3 + 1));
                this.addEffect(_loc_2, _loc_3);
                _loc_3++;
            }
            return;
        }// end function

        private function add3dRole(param1:int, param2:SMainCityPositon) : void
        {
            var _loc_3:SMiniPlayer = null;
            var _loc_4:Model3dBasePanel = null;
            var _loc_5:EntityInfo = null;
            var _loc_6:int = 0;
            if (this._rect3d)
            {
                _loc_3 = param2.officer;
                _loc_5 = Cache.instance.role.roleEntityInfo;
                _loc_6 = MainCityCache.getPostionClothIdByType(param2.positon);
                _loc_4 = UICompomentPool.getUICompoment(Model3dBasePanel);
                _loc_4.rect3d = this._rect3d;
                _loc_4.addRoleModel(_loc_3.career, _loc_3.sex, _loc_6, 0, 0, 0, 0, param1 * 170 + 100, Math.abs(param1 - 2) * 70 + 280, 1.4);
                this.playerVec.push(_loc_4);
            }
            return;
        }// end function

        private function addEffect(param1:int, param2:int) : void
        {
            var _loc_3:TTitle = null;
            var _loc_4:EffectPlayer = null;
            if (this._rect3d)
            {
                _loc_3 = TitleConfig.instance.getInfoById(200200 + param2);
                _loc_4 = EffectPlayerPool.instance.getEffectPlayer(_loc_3.icon, null, this._rect3d.renderList, false);
                _loc_4.play();
                var _loc_5:int = 1;
                _loc_4.scaleZ = 1;
                var _loc_5:* = _loc_5;
                _loc_4.scaleY = _loc_5;
                _loc_4.scaleX = _loc_5;
                this._rect3d.addObject3d(_loc_4, param1 * 170 + 100, Math.abs(param1 - 2) * 70 + 60);
                this._effectVec.push(_loc_4);
            }
            return;
        }// end function

        public function updateList(param1:Object) : void
        {
            var _loc_3:int = 0;
            var _loc_4:SMainCityPositon = null;
            var _loc_5:MainCityPostRender = null;
            var _loc_6:int = 0;
            this.clear3dRole();
            var _loc_2:* = Cache.instance.mainCity.sMainCityPositons;
            if (_loc_2)
            {
                while (_loc_6 < this._postList.length)
                {
                    
                    _loc_5 = this._postList[_loc_6];
                    _loc_3 = this._posArr[_loc_6];
                    _loc_4 = Cache.instance.mainCity.getPostionByPosType(_loc_3);
                    _loc_5.data = _loc_4;
                    if (_loc_4)
                    {
                        this.add3dRole(_loc_6, _loc_4);
                    }
                    _loc_6++;
                }
            }
            return;
        }// end function

    }
}
